<?php

namespace App\Admin\Actions\Loding;
use App\Models\yb\NetworkGoodsOrderModel;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;


class OrderAudit extends RowAction
{
    public $name = '审核';

    /**
     * @param Model $model
     * @return string
     */
    public function handle(Model $model, Request $request)
    {
        $type = $request->get('type');

        $content = $request->get('content');

        if($type == 1){
            $status = 3;
        }else{
            $status = 2;
        }

        NetworkGoodsOrderModel::where(['id'=>$model->id])->update([
            'status' => $status,
            'remark' => $content
        ]);

        return $this->response()->success('操作成功')->refresh();

    }

    /**
     * @param $star
     * @return string
     */
    public function display($id)
    {
        return  '<button type="button" class="btn btn-xs btn-info btn-flat">审核</button>';
    }


    public function form()
    {
        $this->radio('type', '类型')->options([1 => '通过',2=>'驳回'])->required()->default(1);

        $this->textarea('content','备注');

    }

}